#ifndef APPCONTROLLER_H
#define APPCONTROLLER_H
#include <QThread>
#include <QUdpSocket>

class AppController;
class udpSenderAndReceiver: public QThread
{
    Q_OBJECT
public:
    udpSenderAndReceiver(AppController *controller);
    ~udpSenderAndReceiver();

    int StartBroadCastSocket();
    void AbortBroadCastSocket();

    int SendData(QByteArray &data);
    int ErrorCode();

protected:
    void run();


public slots:
    void OnReceiveCastData();
private:
    AppController*  m_Controller;
    QUdpSocket*  m_UdpSocket;
};

class AppController: public QObject
{
    Q_OBJECT
public:
    enum RunStatus
    {
        Starting,
        Abort,
    };

    AppController();
    ~AppController();

    static AppController* Instance();
    static void Destroy();

    void Init();
    int SendData(QByteArray &data);
    void ResetController();
    int ErrorCode();
    int StartController();
    void StopController();

    AppController::RunStatus Status();

signals:
    void ReceiveData(QByteArray& data);

private:
    udpSenderAndReceiver* m_SenderAndReciver = nullptr;


};

#endif // APPCONTROLLER_H
